package com.why.simpleboot.core.boot;

import com.why.simpleboot.core.annotation.applicationcontext.EnableSimpleBootApplication;

import com.why.simpleboot.core.boot.starter.SimpleBootStarter;
import com.why.simpleboot.core.common.utils.SimpleReflectUtils;

import java.util.Objects;

/**
 * @program: why-simpleboot-framework
 * @description:
 * @author: @why
 * @create: 2021-07-03 20:20
 **/
public class SimpleBootApplication {
    /**
     * 服务启动类
     * @param startClass
     */
    public static void run(Class<?> startClass) {
        EnableSimpleBootApplication bootApplication = startClass.getAnnotation(EnableSimpleBootApplication.class);
        if (Objects.isNull(bootApplication)) {
            throw new NullPointerException("not found annotation:EnableSimpleBootApplication");
        } else {
            Class<? extends SimpleBootStarter> starter = bootApplication.ServerStarter();
            Object start = SimpleReflectUtils.getInstance(starter);
            if (Objects.nonNull(start)) {
                SimpleBootStarter simpleBootStarter = (SimpleBootStarter) start;
                simpleBootStarter.initSimpleBoot(startClass);
            } else {
                throw new NullPointerException("not found SimpleBootStarter!");
            }
        }


    }
}
